package cn.wk.dao.impl;

import cn.wk.dao.AdminsDao;
import cn.wk.entity.Admins;
import cn.wk.util.JDBCUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import java.util.List;

public class AdminDaolmpl implements AdminsDao {
    private JdbcTemplate template=new JdbcTemplate(JDBCUtil.getDataSource());
    @Override
    public List<Admins> getAllAmin(Object...obj) {
        String sql="select * from admins limit ?,?";
        List<Admins> list=  template.query(sql, new BeanPropertyRowMapper<>(Admins.class),obj);
        return list;
    }
    @Override
    public int  CountSize(){
        String sql="select count(*) from admins";
        int b=template.queryForObject(sql,Integer.class);
        return b;
    }

    @Override
    public int AddAdmins(Object... obj) {
        String sql="insert admins values(null,?,?,?,?,?,?,?,?)";
        int b=template.update(sql,obj);
        return b;
    }

    @Override
    public int MidffAdmins(Object... obj) {
        String sql="update admins set apwd=?,aname=?,agender=?,address=?,atel=?,aemail=?,status=? where aid=?";
        int b=template.update(sql,obj);
        return b;
    }

    @Override
    public int DelAdmins(Object... obj) {
       return 0;
    }



    @Override
    public Admins findAdminById(int aid) {
        String sql="select * from admins where aid=?";
      Admins admins=  template.queryForObject(sql,new BeanPropertyRowMapper<>(Admins.class),aid);
        return admins;
    }
    @Override
    public Admins findAdminByNo(String no) {
        String sql="select * from admins where ano=?";
        Admins admins=  template.queryForObject(sql,new BeanPropertyRowMapper<>(Admins.class),no);
        return admins;
    }


}
